/* reading patches */

/* $Id: pch.h,v 1.11 2003/05/20 13:56:03 eggert Exp $ */

/* Copyright (C) 1986, 1987, 1988 Larry Wall

   Copyright (C) 1990, 1991, 1992, 1993, 1997, 1998, 1999, 2000, 2001,
   2002, 2003 Free Software Foundation, Inc.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2, or (at your option)
   any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; see the file COPYING.
   If not, write to the Free Software Foundation,
   59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */

#ifndef PCH_H_
#define PCH_H_

#define XTERN extern
#include "common.h"
#undef XTERN

class CReadPatch
{
public:
  static LINENUM pch_end ();
  static LINENUM pch_first ();
  static LINENUM pch_hunk_beg ();
  static char const *pch_c_function ();
  static LINENUM pch_newfirst ();
  static LINENUM pch_prefix_context ();
  static LINENUM pch_ptrn_lines ();
  static LINENUM pch_repl_lines ();
  static LINENUM pch_suffix_context ();
  static bool pch_swap ();
  static bool pch_write_line (LINENUM, FILE *);
  static bool there_is_another_patch ();
  static char *pfetch (LINENUM);
  static char pch_char (LINENUM);
  static int another_hunk (enum diff, bool);
  static int pch_says_nonexistent (bool which);
  static size_t pch_line_len (LINENUM);
  static time_t pch_timestamp (bool);
  static void do_ed_script (FILE *);
  static void open_patch_file (char const *);
  static void re_patch ();
  static void set_hunkmax ();

private:
  static bool grow_hunkmax ();
  static enum diff intuit_diff_type ();
  static void next_intuit_at (file_offset file_pos, LINENUM file_line);
  static void skip_to (file_offset file_pos, LINENUM file_line);
  static void malformed ();
  static size_t get_line ();
  static size_t pget_line (int indent, int rfc934_nesting, bool strip_trailing_cr, bool pass_comments_through);
  static char* scan_linenum (char* s0, LINENUM* linenum);
  static bool incomplete_line ();

private:
  static FILE *pfp;			            /* patch file pointer */
  static int p_says_nonexistent[2];	/* [0] for old file, [1] for new:
                                        0 for existent and nonempty,
                                        1 for existent and probably (but not necessarily) empty,
                                        2 for nonexistent */
  static int p_rfc934_nesting;		  /* RFC 934 nesting level */
  static time_t p_timestamp[2];		  /* timestamps in patch headers */
  static off_t p_filesize;		      /* size of the patch file */
  static LINENUM p_first;			      /* 1st line number */
  static LINENUM p_newfirst;		    /* 1st line number of replacement */
  static LINENUM p_ptrn_lines;		  /* # lines in pattern */
  static LINENUM p_repl_lines;		  /* # lines in replacement text */
  static LINENUM p_end;	      	    /* last line in hunk */
  static LINENUM p_max;			        /* max allowed value of p_end */
  static LINENUM p_prefix_context;	/* # of prefix context lines */
  static LINENUM p_suffix_context;	/* # of suffix context lines */
  static LINENUM p_input_line;		  /* current line # from patch file */
  static char **p_line;			        /* the text of the hunk */
  static size_t *p_len;			        /* line length including \n if any */
  static char *p_Char;			        /* +, -, and ! */
  static LINENUM hunkmax;	          /* size of above arrays */
  static int p_indent;			        /* indent to patch */
  static bool p_strip_trailing_cr;	/* true if stripping trailing \r */
  static bool p_pass_comments_through;	/* true if not ignoring # lines */
  static file_offset p_base;		    /* where to intuit this time */
  static LINENUM p_bline;			      /* line # of p_base */
  static file_offset p_start;		    /* where intuit found a patch */
  static LINENUM p_sline;			      /* and the line number for it */
  static LINENUM p_hunk_beg;		    /* line number of current hunk */
  static LINENUM p_efake;		        /* end of faked up lines--don't free */
  static LINENUM p_bfake;     		  /* beg of faked up lines */
  static char *p_c_function;		    /* the C function a hunk is in */
};

#endif // PCH_H_